package edu.umuc.cmsc495_final_project;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTree;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.JEditorPane;

public class kitchenGUI extends JFrame implements allGUI, TableModelListener {

	JTree patronWaitTree;

	DefaultMutableTreeNode reservation;
	DefaultMutableTreeNode walkin;
	DefaultMutableTreeNode bar;

	public kitchenGUI() {

System.out.println("opening hostess panel");
		
		//
		setName("Kitchen");
		setBounds(0,panelStartY,panelWidth,panelEndHeight);
		setVisible(true);
		setLayout(new BorderLayout());
		removeNotify();  
		setUndecorated(true);  
		addNotify();  
		
		// show main body
		mainBody();
	}

	//
	public void mainBody() {

		JTable kitchenDetails = new JTable(new MyTableModel());
		kitchenDetails.getModel().addTableModelListener(this);
		kitchenDetails.getColumnModel().getColumn(0).setPreferredWidth(50);
		kitchenDetails.getColumnModel().getColumn(1).setPreferredWidth(50);
		kitchenDetails.getColumnModel().getColumn(2).setPreferredWidth(150);
		kitchenDetails.getColumnModel().getColumn(3).setPreferredWidth(50);
		kitchenDetails.getColumnModel().getColumn(4).setPreferredWidth(100);
		kitchenDetails.getColumnModel().getColumn(5).setPreferredWidth(50);

		// Put the table display pane in a scroll pane incase items are too big
		JScrollPane tableScrollPane = new JScrollPane(kitchenDetails);

		// notes are
		JPanel detailPane = new JPanel(new GridBagLayout());

		// setup for layout
		GridBagConstraints c = new GridBagConstraints();

		//
		JLabel lblDetail = new JLabel("Details", JLabel.CENTER);
		lblDetail.setFont(font);
		c.fill = GridBagConstraints.HORIZONTAL;
		c.ipady = 0;
		c.weightx = 1;
		c.gridy = 1;
		detailPane.add(lblDetail, c);

		// table display area
		JEditorPane notesPane = new JEditorPane();
		// notesPane.setEditable(false);
		// Put the table display pane in a scroll pane incase items are too big
		JScrollPane notesScrollPane = new JScrollPane(notesPane,
				JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		// c.fill = GridBagConstraints.REMAINDER;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.ipady = (int) (panelHeight * .70);
		c.weightx = 1;
		c.weighty = 2;
		c.gridy = 2;
		detailPane.add(notesScrollPane, c);

		JButton newNote = new JButton("New Note");
		c.fill = GridBagConstraints.HORIZONTAL;
		c.ipady = 80;
		c.weightx = 1;
		c.gridy = 3;
		c.insets = new Insets(5, 5, 5, 5); // top padding
		detailPane.add(newNote, c);

		JButton delNote = new JButton("Delete Note");
		c.fill = GridBagConstraints.HORIZONTAL;
		c.ipady = 80;
		c.weightx = 1;
		c.gridy = 4;
		c.insets = new Insets(5, 5, 5, 5); // top padding
		detailPane.add(delNote, c);

		// full split pane window
		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
				tableScrollPane, detailPane);// table display left, reservation
												// window right
		splitPane.setOneTouchExpandable(true);
		splitPane.setDividerLocation((int) (panelWidth * .80));

		// add to hostess frame
		add(splitPane);
	}

	@Override
	public void tableChanged(TableModelEvent arg0) {
		// TODO
		int row = arg0.getFirstRow();
		int column = arg0.getColumn();
		TableModel model = (TableModel) arg0.getSource();
		String columnName = model.getColumnName(column);
		Object data = model.getValueAt(row, column);

		// TODO Do something with the data...

	}
}

// TODO lots here to do..
class MyTableModel extends AbstractTableModel {
	private String[] columnNames = { "Order #", "Table #", "Item Ordered",
			"Quantity", "Description", "Alergies ?" };
	private Object[][] data = {};//

	public int getColumnCount() {
		return columnNames.length;
	}

	public int getRowCount() {
		return data.length;
	}

	public String getColumnName(int col) {
		return columnNames[col];
	}

	public Object getValueAt(int row, int col) {
		return data[row][col];
	}

	@SuppressWarnings("unchecked")
	public Class getColumnClass(int c) {
		return getValueAt(0, c).getClass();
	}

	public void setValueAt(Object value, int row, int col) {
		data[row][col] = value;
		fireTableCellUpdated(row, col);
	}
}